package com.xhcl.web.controller.system;


import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TSrhsZyk;
import com.xhcl.system.service.ITSrhsZykService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.common.core.domain.Stree;

/**
 * 摘要库Controller
 * 
 * @author xhcl
 * @date 2020-11-15
 */
@Controller
@RequestMapping("/system/zyk")
public class TSrhsZykController extends BaseController
{
    private String prefix = "system/zyk";

    @Autowired
    private ITSrhsZykService tSrhsZykService;

    @RequiresPermissions("system:zyk:view")
    @GetMapping()
    public String zyk()
    {
        return prefix + "/zyk";
    }

    /**
     * 查询摘要库树列表
     */
    @RequiresPermissions("system:zyk:list")
    @PostMapping("/list")
    @ResponseBody
    public List<TSrhsZyk> list(TSrhsZyk tSrhsZyk)
    {
        List<TSrhsZyk> list = tSrhsZykService.selectTSrhsZykList(tSrhsZyk);
        return list;
    }

    /**
     * 导出摘要库列表
     */
    @RequiresPermissions("system:zyk:export")
    @Log(title = "摘要库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsZyk tSrhsZyk)
    {
        List<TSrhsZyk> list = tSrhsZykService.selectTSrhsZykList(tSrhsZyk);
        ExcelUtil<TSrhsZyk> util = new ExcelUtil<TSrhsZyk>(TSrhsZyk.class);
        return util.exportExcel(list, "zyk");
    }

    /**
     * 新增摘要库
     */
    @GetMapping(value = { "/add/{zybm}", "/add/" })
    public String add(@PathVariable(value = "zybm", required = false) String zybm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(zybm))
        {
            mmap.put("tSrhsZyk", tSrhsZykService.selectTSrhsZykById(zybm));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存摘要库
     */
    @RequiresPermissions("system:zyk:add")
    @Log(title = "摘要库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSrhsZyk tSrhsZyk)
    {
        return toAjax(tSrhsZykService.insertTSrhsZyk(tSrhsZyk));
    }

    /**
     * 修改摘要库
     */
    @GetMapping("/edit/{zybm}")
    public String edit(@PathVariable("zybm") String zybm, ModelMap mmap)
    {
        TSrhsZyk tSrhsZyk = tSrhsZykService.selectTSrhsZykById(zybm);
        mmap.put("tSrhsZyk", tSrhsZyk);
        return prefix + "/edit";
    }

    /**
     * 修改保存摘要库
     */
    @RequiresPermissions("system:zyk:edit")
    @Log(title = "摘要库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSrhsZyk tSrhsZyk)
    {
        return toAjax(tSrhsZykService.updateTSrhsZyk(tSrhsZyk));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:zyk:remove")
    @Log(title = "摘要库", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{zybm}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("zybm") String zybm)
    {
        return toAjax(tSrhsZykService.deleteTSrhsZykById(zybm));
    }

    /**
     * 选择摘要库树
     */
    @GetMapping(value = { "/selectZykTree/{zybm}", "/selectZykTree/" })
    public String selectZykTree(@PathVariable(value = "zybm", required = false) String zybm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(zybm))
        {
            mmap.put("tSrhsZyk", tSrhsZykService.selectTSrhsZykById(zybm));
        }
        return prefix + "/tree";
    }

    /**
     * 加载摘要库树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Stree> treeData()
    {
        List<Stree> ztrees = tSrhsZykService.selectTSrhsZykTree();
        return ztrees;
    }
}
